Beef up some various documentation
authorAlex Crichton <alex@alexcrichton.com>
Thu, 21 Aug 2014 18:34:05 +0000 (11:34 -0700)
committerAlex Crichton <alex@alexcrichton.com>
Thu, 21 Aug 2014 18:34:05 +0000 (11:34 -0700)
.travis.yml
src/doc/source/guide.md
src/doc/source/index.md
src/doc/source/manifest.md
src/doc/source/native-build.md

index f1ee1cbd95f9abb293c2a874c79fb45f594593f9..3e97db1f2b4a4b86fc5101a329568b96354b4eaf 100644 (file)
@@ -14,8 +14,7 @@ after_success: |
   (cd src/doc &&
    bundle &&
    bundle exec middleman build) &&
-  echo crates.io >> src/doc/build/CNAME &&
-  sudo pip install ghp-import
+  sudo pip install ghp-import &&
   ghp-import -n src/doc/build &&
   git push -f https://${TOKEN}@github.com/${TRAVIS_REPO_SLUG}.git gh-pages
 env:
index 2ab95458e7ce8d689fdb35d870ce3f22c80353ba..2678b652860363deddbc4aa8ba1808aa1365bc41 100644 (file)
@@ -60,7 +60,7 @@ authors = ["Yehuda Katz <wycats@example.com>"]
 ```
 
 This is called a **manifest**, and it contains all of the metadata that Cargo
-needs to compile your project. 
+needs to compile your project.
 
 Here's what's in `src/main.rs`:
 
index 8ac8f2e55d2f27ed7829b49bc343b84804a39219..f5a6eaa71455ba89949e8c756678e0ae4e699a4c 100644 (file)
@@ -13,9 +13,9 @@ $ curl https://static.rust-lang.org/rustup.sh | sudo bash
 
 This will get you the latest Rust nightly for your platform along with
 the latest Cargo. You should run this script almost every day to get the latest updates.
-   
+
 If you are on Windows, you can directly download the latest [Rust](http://static.rust-lang.org/dist/rust-nightly-install.exe)
-and [Cargo](http://static.rust-lang.org/cargo-dist/cargo-nightly-i686-pc-mingw32.tar.gz) nightlies.  
+and [Cargo](http://static.rust-lang.org/cargo-dist/cargo-nightly-i686-pc-mingw32.tar.gz) nightlies.
 
 Alternatively, you can build Cargo from source.
 
@@ -24,11 +24,12 @@ Alternatively, you can build Cargo from source.
 To start a new project with Cargo, use `cargo new`:
 
 ```shell
-$ cargo new hello_world --bin
+$ cargo new hello_world --bin --git
 ```
 
 We're passing `--bin` because we're making a binary program: if we
-were making a library, we'd leave it off.
+were making a library, we'd leave it off. We also pass `--git` to auto-generate
+a `.gitignore` and set up the git repository, but nothing will be committed.
 
 Let's check out what Cargo has generated for us:
 
@@ -54,7 +55,7 @@ authors = ["Yehuda Katz <wycats@example.com>"]
 ```
 
 This is called a **manifest**, and it contains all of the metadata that Cargo
-needs to compile your project. 
+needs to compile your project.
 
 Here's what's in `src/main.rs`:
 
index 4047a98d4bc4da8754ba00167f82ec6c85054f86..c000066a0f43d507b4bcfe511812e65aad6dc06a 100644 (file)
@@ -30,9 +30,11 @@ basic rules:
 
 You can specify a script that Cargo should execute before invoking
 `rustc`. You can use this to compile C code that you will [link][1] into
-your Rust code, for example.
+your Rust code, for example. More information can be found in the building
+non-rust code [guide][2]
 
 [1]: http://doc.rust-lang.org/rust.html#external-blocks
+[2]: native-build.html
 
 ```toml
 [package]
@@ -40,6 +42,30 @@ your Rust code, for example.
 build = "make"
 ```
 
+```toml
+[package]
+# ...
+
+# Specify two commands to be run sequentially
+build = ["./configure", "make"]
+```
+
+## The `exclude` Field (optional)
+
+You can explicitly specify to Cargo that a set of globs should be ignored for
+the purposes of packaging and rebuilding a package. The globs specified in this
+field identify a set of files that are not included when a package is published
+as well as ignored for the purposes of detecting when to rebuild a package.
+
+If a VCS is being used for a package, the `exclude` field will be seeded with
+the VCS's ignore settings (`.gitignore` for git for example).
+
+```toml
+[package]
+# ...
+exclude = ["build/**/*.o", "doc/**/*.html"]
+```
+
 # The `[dependencies.*]` Sections
 
 You list dependencies using `[dependencies.<name>]`. For example, if you
@@ -67,6 +93,15 @@ You can specify the source of a dependency in one of two ways at the moment:
 
 Soon, you will be able to load packages from the Cargo registry as well.
 
+# The `[dev-dependencies.*]` Sections
+
+The format of this section is equivalent to `[dependencies.*]`. Dev-dependencies
+are not used when compiling a package for building, but are used for compiling
+tests and benchmarks.
+
+These dependencies are *not* propagated to other packages which depend on this
+package.
+
 # The Project Layout
 
 If your project is an executable, name the main source file `src/main.rs`.
@@ -88,6 +123,8 @@ the `target` directory.
   *.rs
 ▾ tests/        # (optional) integration tests
   *.rs
+▾ benches/      # (optional) benchmarks
+  *.rs
 ```
 
 # Examples
@@ -110,7 +147,46 @@ When you run `cargo test`, Cargo will:
   <library-name>` like any other code that depends on it.
 * Compile your library's examples.
 
-# Building Dynamic Libraries
+# Configuring a target
+
+Both `[[bin]]` and `[lib]` sections support similar configuration for specifying
+how a target should be built. The example below uses `[lib]`, but it also
+applies to all `[[bin]]` sections as well. All values listed ar the defaults for
+that option unless otherwise specified.
+
+```toml
+[package]
+# ...
+
+[lib]
+
+# The name of a target is the name of the library that will be generated. This
+# is defaulted to the name of the package or project.
+name = "foo"
+
+# This field points at where the crate is located, relative to the Cargo.toml.
+path = "src/lib.rs"
+
+# A flag for enabling unit tests for this target. This is used by `cargo test`.
+test = true
+
+# A flag for enabling documentation tests for this target. This is only
+# relevant for libraries, it has no effect on [[bin]] sections. This is used by
+# `cargo test`.
+doctest = true
+
+# A flag for enabling benchmarks for this target. This is used by `cargo bench`.
+bench = true
+
+# A flag for enabling documentation of this target. This is used by `cargo doc`.
+doc = true
+
+# If the target is meant to be a compiler plugin, this field must be set to true
+# for cargo to correctly compile it and make it available for all dependencies.
+plugin = false
+```
+
+# Building Dynamic or Static Libraries
 
 If your project produces a library, you can specify which kind of
 library to build by explicitly listing the library in your `Cargo.toml`:
@@ -118,13 +194,13 @@ library to build by explicitly listing the library in your `Cargo.toml`:
 ```toml
 # ...
 
-[[lib]]
+[lib]
 
 name = "..."
-crate-types = [ "dylib" ]
+# this could be "staticlib" as well
+crate-type = ["dylib"]
 ```
 
-The available options are `dylib` and `rlib`. You should only use
-this option in a project. Cargo will always compile **packages**
-(dependencies) based on the requirements of the project that includes
-them.
+The available options are `dylib`, `rlib`, and `staticlib`. You should only use
+this option in a project. Cargo will always compile **packages** (dependencies)
+based on the requirements of the project that includes them.
index cbee444b579969bc1da1125251a84e7234fcae95..93b94da2a458074b68171a3ba7749decd85d5443 100644 (file)
@@ -34,6 +34,8 @@ Here's what you need to know:
   directory.
 * The actual location of `$OUT_DIR` is
   `/path/to/project/target/native/$your-out-dir`.
+* The target triple that the build command should compile for is specified by
+  the `TARGET` environment variable.
 
 What this means is that the normal workflow for build dependencies is:
 
@@ -42,9 +44,11 @@ What this means is that the normal workflow for build dependencies is:
   into the provided `$OUT_DIR`.
 * The next time a user runs `cargo build`, if the dependency has not
   changed (via `cargo update <your-package>`), Cargo will reuse the
-  output you provided before.
+  output you provided before. Your build command will not be invoked.
 * If the user updates your package to a new version (or git revision),
-  Cargo will wipe the old `$OUT_DIR` and re-invoke your build script.
+  Cargo will **not** remove the old `$OUT_DIR` will re-invoke your build script.
+  Your build script is responsible for bringing the state of the old directory
+  up to date with the current state of the input files.
 
 In general, build scripts may not be as portable as we'd like today. We
 encourage package authors to write build scripts that can work in both
@@ -56,5 +60,57 @@ enable portable external compilation and linkage against system
 packages. We intend for it to eventually serve this purpose for Cargo
 projects.
 
-[1]: http://doc.rust-lang.org/rust.html#runtime-services,-linkage-and-debugging
+[1]: http://doc.rust-lang.org/rust.html#linkage
 [2]: https://github.com/alexcrichton/link-config
+
+# A complete example
+
+The code blocks below lay out a cargo project which has a small and simple C
+dependency along with the necessary infrastructure for linking that to the rust
+program.
+
+```toml
+# Cargo.toml
+[package]
+
+name = "hello-world-from-c"
+version = "0.1.0"
+authors = [ "wycats@gmail.com" ]
+build = "make -C build"
+```
+
+```make
+# build/Makefile
+
+# Support cross compilation to/from 32/64 bit.
+ARCH := $(word 1, $(subst -, ,$(TARGET)))
+ifeq ($(ARCH),i686)
+CFLAGS += -m32 -fPIC
+else
+CFLAGS += -m64 -fPIC
+endif
+
+all:
+    $(CC) $(CFLAGS) hello.c -c -o $(OUT_DIR)/hello.o
+    $(AR) crus $(OUT_DIR)/libhello.a $(OUT_DIR)/hello.o
+
+```
+
+```c
+// build/hello.c
+int foo() { return 1; }
+```
+
+```rust
+// src/main.rs
+
+#[link(name = "hello", kind = "static")]
+extern {
+    fn foo() -> i32;
+}
+
+fn main() {
+    let number = unsafe { foo() };
+    println!("found {} from C!", number);
+}
+```